<!DOCTYPE HTML>
<%@page import="java.util.Iterator"%>
<%@page import="shop.vo.AddressBean"%>
<%@page import="java.util.List"%>
<%@page import="shop.factory.DAOFactory"%>
<%@page import="shop.vo.UserBean"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<meta charset="UTF-8" />
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/address.css" />
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<title>地址簿</title>
</head>
<%
	String str = (String)session.getAttribute("user");
	UserBean user = new UserBean();
	user.setUser_name(str);
	int id = DAOFactory.getIUserDAOInstance().findId(user);
	List<AddressBean> list = DAOFactory.getIAddressDAOInstance().findAddr(id);
	Iterator<AddressBean> it = list.iterator();
%>
<body>
	<nav class="navbar navbar-default" role="navigation">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target="#bs-example-navbar-collapse-1">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
		</div>
		<div class="collapse navbar-collapse"
			id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
				<li class="active"><a href="../index.jsp">首页</a></li>
				<li><a href="<%=request.getContextPath() %>/OrderServlet?action=MyOrder"> <img src="../images/order.png" /> 我的订单
				</a></li>
				<li></li>
				<li><a href="<%=request.getContextPath() %>/OrderServlet?action=MyCart"> <img src="../images/car.png" /> 我的购物车
				</a></li>
				<li><a href="<%=request.getContextPath() %>/FavoriteServlet?action=MyFav"> <img src="../images/favorite.png" /> 我的收藏
				</a></li>
				<li><a href="<%=request.getContextPath() %>/AddressServlet?action=MyAddress"> <img src="../images/address.png" /> 我的地址簿
				</a></li>
			</ul>

			<ul class="nav navbar-nav navbar-right">
				<li><a href="<%=request.getContextPath() %>/UserServlet?action=xinxi"><span id="huanying">欢迎光临，游客</span></a></li>
				<li><a href="../Login/login.jsp">登陆</a></li>
				<li><a href="../Login/regist.jsp">注册</a></li>
				<li><a href="<%=request.getContextPath() %>/UserServlet?action=logout" class="active" onclick="return confirm('确认退出?')">退出</a></li>
			</ul>
		</div>
	</nav>

	<div class="col-md-12">
		<h2 class="tittle">我的地址簿</h2>
		<div class="page-header"></div>
	</div>

	<div class="container">
		<div class="container">
			<table class="table .table-striped">
				<caption>
					<a href="<%=request.getContextPath() %>/AddressServlet?action=addAddr" class="btn btn-primary">添加新地址</a>
				</caption>
				<thead>
					<tr>
						<th>编号</th>
						<th>收货人姓名</th>
						<th>收货人地址</th>
						<th>收货人电话</th>
						<th>收货人邮编</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<%
						while (it.hasNext()) {
							AddressBean addr = it.next();
					%>
					<tr>
						<td><%=addr.getAddr_id() %></td>
						<td><%=str %></td>
						<td><%=addr.getAddr_address() %></td>
						<td><%=addr.getAddr_mobile() %></td>
						<td><%=addr.getAddr_zip() %></td>
						<td><span id="delete"><a href="<%=request.getContextPath()%>/AddressServlet?action=delete&id=<%=addr.getAddr_id()%>">删除</a></span> <span
							id="change"><a href="<%=request.getContextPath()%>/AddressServlet?action=xiugai&id=<%=addr.getAddr_id()%>">修改</a></span></td>
					</tr>
					<%
						}
					%>
				</tbody>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">
<%
	String str0 = (String)session.getAttribute("user");
	if (session.getAttribute("user") != null) {
%>
document.getElementById("huanying").innerHTML = "欢迎光临，<%=str0%>";
<%
	} else {
%>
document.getElementById("huanying").innerHTML = "欢迎光临，游客";
<%
	}
%>
</script>
</html>